1) We want to show as much data as possible to see where the data gaps are and what we can do so far
2) for the items as "canvasdummyname" we have an exported csv with the IP adressses to try to match that
3) Then we can decide how to edit the xAPI process
import json
import plotly as plotly
import plotly.graph_objects as go
with open('Sample LRS rinnuja.json') as json_file:
xapiData = json.load(json_file)
print("data tyoe of json statements below: \n" + str(type(xapiData)))
print("length of data: \n " + str(len(xapiData)))
print("statement at index 0: \n " + str(xapiData[0]))
print("acessing key and result in statement at index 0: \n " + str(xapiData[0]['object']['id']))
data tyoe of json statements below:
<class 'list'>
length of data:
21343
statement at index 0:
{'actor': {'name': 'canvas test name', 'mbox': 'mailto:canvastestnamehere@gmail.com'}, 'verb': {'id': 'http://adlnet.gov/expapi/verbs/initialized', 'display': {'en-US': 'initialized'}}, 'object': {'id': 'https://elearn.ucr.edu/courses/3730', 'definition': {'name': {'en-US': 'Cal Labs Module 1: Method of Joints'}, 'description': {'en-US': 'Student has started module 1: Method of joints'}, 'type': 'http://adlnet.gov/expapi/activities/course'}, 'objectType': 'Activity'}, 'result': {'duration': 'PT2S'}, 'id': '4e66ecaa-48f6-4b14-b948-f15068983b33', 'timestamp': '2021-06-15T02:14:02.632Z', 'stored': '2021-06-15T02:14:02.632Z', 'authority': {'objectType': 'Agent', 'account': {'homePage': 'https://xcite-testing.lrs.io/keys/authorization', 'name': 'authorization'}}}
acessing key and result in statement at index 0:
https://elearn.ucr.edu/courses/3730
#lets try to get a bar chart that will do show the number of unique actors Y vs verbs X
#iterate thru data and save
actors = [] #a list ("array") of strings
for eachStatement in xapiData:
actors.append(eachStatement['actor']['name'])
#print(actors)
#print(actors[0])
verbs = []
for eachStatement in xapiData:
verbs.append(eachStatement['verb']['display']['en-US'])
#print(verbs)
#using Basic Bar Chart with plotly.graph_objects
fig = go.Figure([go.Bar(x= verbs, y= actors)])
fig.show()
#You do see the bars, but the color are grayed out because each bar is composed of hundreds of stacked rectangles with a tiny space between them
#https://stackoverflow.com/questions/66177855/bar-colors-in-plotly-bar-chart-appear-grayed-out
Above graph has to many entries, when need to trim it down.
#using set()
# to remove duplicated
# from list
trimmed_actors = list(set(actors))
trimmed_verbs = list(set(verbs))
fig = go.Figure([go.Bar(x= trimmed_verbs, y= trimmed_actors)])
fig.show()
Looks better but still isn't what i want...
timesVisted = [0,0,0,0]
for eachStatement in xapiData:
for eachVerb in range(4):
#print(eachVerb) since eachVerb is a string, whenn doing for eachVerb in trimmed_Verbs it doesnt work an index
if eachStatement['verb']['display']['en-US'] == trimmed_verbs[eachVerb]:
timesVisted[eachVerb] += 1
#print(timesVisted[0])
fig = go.Figure([go.Bar(x= trimmed_verbs, y= timesVisted)],
layout=go.Layout(title=go.layout.Title(text="Verb vs Times visited")) )
fig.show()
Here's the data output from Veracity GUI graph builder. I chose to make each unqiue bar for every verb encountered where the matching records is the object id. The Output is below.
"data": [
{
"_id": "answered",
"count": 12971,
"canonical": {
"display": "answered"
},
{
"_id": "viewed",
"count": 7339,
"canonical": {
"display": "viewed"
},
{
"_id": "initialized",
"count": 677,
"canonical": {
"display": "initialized"
},
{
"_id": "exited",
"count": 338,
"canonical": {
"display": "exited"
}
]
Only viewed is slightly off is this is due to the fact that some tests where done after I downloaded the json data. But the method above worked.
#import pandas as pd
#it would be easier to organize the statements inside the data frame... well circle back. it means clealing up the data.
#df =pd.DataFrame(xapiData) #the result inside fs is messy and unhelpfull. Its needs to be simplified
#run this below to export as html and keep graph interactivity
plotly.offline.init_notebook_mode()
Next steps is try to organize the data